package com.ding.dailyup.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.ding.dailyup.emum.StrategyStatusEnum;
import com.ding.dailyup.exception.BOException;
import com.ding.dailyup.model.StockStrategy;
import com.ding.dailyup.repository.StockStrategyRepository;
import com.google.common.collect.Lists;

@Service
public class StockStrategyService {
	@Autowired
	private StockStrategyRepository stockStrategyRepository;

	public List<StockStrategy> listStrategies() {
		return stockStrategyRepository
				.findByStatusNotOrderById(StrategyStatusEnum.DEL.status())
				.orElse(Lists.newArrayList());
	}

	public StockStrategy findById(Long strategyId) {
		return stockStrategyRepository.findById(strategyId)
				.orElseThrow(() -> new BOException("策略不存在!"));
	}
}
